﻿using System;
using System.Data;
using System.Collections.Generic;
using Things.Common;
using Things.Model;
using Things.DALFactory;
using Things.IDAL;
namespace Things.BLL
{
    /// <summary>
    /// GoodsDescription
    /// </summary>
    public partial class GoodsDescription
    {
        private readonly IGoodsDescription dal = DataAccess.CreateGoodsDescription();
        public GoodsDescription()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(Guid GoodsID)
        {
            return dal.Exists(GoodsID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Things.Model.GoodsDescription model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Things.Model.GoodsDescription model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(Guid GoodsID)
        {

            return dal.Delete(GoodsID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string GoodsIDlist)
        {
            return dal.DeleteList(GoodsIDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Things.Model.GoodsDescription GetModel(Guid GoodsID)
        {

            return dal.GetModel(GoodsID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public Things.Model.GoodsDescription GetModelByCache(Guid GoodsID)
        {

            string CacheKey = "GoodsDescriptionModel-" + GoodsID;
            object objModel = Things.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(GoodsID);
                    if (objModel != null)
                    {
                        int ModelCache = Things.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Things.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Things.Model.GoodsDescription)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Things.Model.GoodsDescription> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Things.Model.GoodsDescription> DataTableToList(DataTable dt)
        {
            List<Things.Model.GoodsDescription> modelList = new List<Things.Model.GoodsDescription>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Things.Model.GoodsDescription model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Things.Model.GoodsDescription();
                    if (dt.Rows[n]["GoodsID"] != null && dt.Rows[n]["GoodsID"].ToString() != "")
                    {
                        model.GoodsID = new Guid(dt.Rows[n]["GoodsID"].ToString());
                    }
                    if (dt.Rows[n]["GoodsDescriptions"] != null && dt.Rows[n]["GoodsDescriptions"].ToString() != "")
                    {
                        model.GoodsDescriptions = dt.Rows[n]["GoodsDescriptions"].ToString();
                    }
                    if (dt.Rows[0]["CreatedDate"] != null && dt.Rows[0]["CreatedDate"].ToString() != "")
                    {
                        model.CreatedDate = DateTime.Parse(dt.Rows[0]["CreatedDate"].ToString());
                    }
                    if (dt.Rows[n]["IsDeleted"] != null && dt.Rows[n]["IsDeleted"].ToString() != "")
                    {
                        if ((dt.Rows[n]["IsDeleted"].ToString() == "1") || (dt.Rows[n]["IsDeleted"].ToString().ToLower() == "true"))
                        {
                            model.IsDeleted = true;
                        }
                        else
                        {
                            model.IsDeleted = false;
                        }
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

